package cn.daniellee.plugin.pr.command;

import cn.daniellee.plugin.pr.PlotRedstone;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;


public class RedstoneCommand implements CommandExecutor {

	@Override
	public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
//		if (strings.length != 0) {
//			// 邀请玩家
//			if (strings[0].equalsIgnoreCase("remain")) {
//				if (strings.length > 1 && commandSender.hasPermission("redstone.command.remain.other")) {
//
//				} else {
//
//				}
//			// 开通权限
//			} else if (strings[0].equalsIgnoreCase("permit") && strings.length > 2 && commandSender.hasPermission("redstone.command.permit")) {
//
//				// 关闭权限
//			} else if (strings[0].equalsIgnoreCase("forbid") && strings.length > 1 && commandSender.hasPermission("redstone.command.forbid")) {
//
//				// 取消任务
//			} else if (strings[0].equalsIgnoreCase("cancel") && strings.length > 1 && commandSender.hasPermission("mission.command.cancel")) {
//				PlayerData playerData = PlotRedstone.getInstance().getStorage().getPlayerByName(strings[1]);
//				if (RedstoneCore.missions.removeIf(item -> item.getInviter().equals(playerData.getName()) || item.getInvitee().equals(playerData.getName()))) {
//					commandSender.sendMessage((PlotRedstone.getInstance().getPrefix() + PlotRedstone.getInstance().getConfig().getString("message.cancel-success", "&eCancel the task successfully.")).replace("&", "§"));
//				} else commandSender.sendMessage((PlotRedstone.getInstance().getPrefix() + PlotRedstone.getInstance().getConfig().getString("message.no-mission", "&eThe player is not performing a mission.")).replace("&", "§"));
//			// 重载插件
//			} else if (strings[0].equalsIgnoreCase("reload") && commandSender.hasPermission("mission.command.reload")) {
//				PlotRedstone.getInstance().reloadConfig();
//				if (PlotRedstone.getInstance().loadConfig()) {
//					commandSender.sendMessage((PlotRedstone.getInstance().getPrefix() + PlotRedstone.getInstance().getConfig().getString("message.reload-success", "&eReload has been successful.")).replace("&", "§"));
//				}
//				// 发送帮助
//			} else sendHelp(commandSender);
//		} else commandSender.sendMessage((PlotRedstone.getInstance().getPrefix() + PlotRedstone.getInstance().getConfig().getString("message.player-only", "&eThe console cannot open the GUI menu.")).replace("&", "§"));
		return true;
	}

	private void sendHelp(CommandSender commandSender) {
		commandSender.sendMessage(("&m&6---&m&a--------&3 : " + PlotRedstone.getInstance().getConfig().getString("prompt-prefix", "&6PartnerMission") + "&3 : &m&a--------&m&6---").replace("&", "§"));

		String mainText =  PlotRedstone.getInstance().getConfig().getString("help.main", "&eOpen the partner mission GUI menu.").replace("&", "§");
		TextComponent mainHelp = new TextComponent("/pm  " + mainText);
		mainHelp.setColor(ChatColor.GRAY);
		mainHelp.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/pm"));
		mainHelp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(mainHelp).color(ChatColor.BLUE).create()));
		commandSender.spigot().sendMessage(mainHelp);

		String inviteText =  PlotRedstone.getInstance().getConfig().getString("help.invite", "&eInvite player to perform missions.").replace("&", "§");
		TextComponent inviteHelp = new TextComponent("/pm invite <player>  " + inviteText);
		inviteHelp.setColor(ChatColor.GRAY);
		inviteHelp.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/pm invite "));
		inviteHelp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(inviteText).color(ChatColor.BLUE).create()));
		commandSender.spigot().sendMessage(inviteHelp);

		String acceptText =  PlotRedstone.getInstance().getConfig().getString("help.accept", "&eAccept invitations from player.").replace("&", "§");
		TextComponent acceptHelp = new TextComponent("/pm accept <player>  " + acceptText);
		acceptHelp.setColor(ChatColor.GRAY);
		acceptHelp.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/pm accept "));
		acceptHelp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(acceptText).color(ChatColor.BLUE).create()));
		commandSender.spigot().sendMessage(acceptHelp);

		String clearText =  PlotRedstone.getInstance().getConfig().getString("help.clear", "&eClear player data.").replace("&", "§");
		TextComponent clearHelp = new TextComponent("/pm clear <player>  " + clearText);
		clearHelp.setColor(ChatColor.GRAY);
		clearHelp.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/pm clear "));
		clearHelp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(clearText).color(ChatColor.BLUE).create()));
		commandSender.spigot().sendMessage(clearHelp);

		String cancelText =  PlotRedstone.getInstance().getConfig().getString("help.cancel", "&eCancel a player's mission.").replace("&", "§");
		TextComponent cancelHelp = new TextComponent("/pm cancel <player>  " + cancelText);
		cancelHelp.setColor(ChatColor.GRAY);
		cancelHelp.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/pm cancel "));
		cancelHelp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(cancelText).color(ChatColor.BLUE).create()));
		commandSender.spigot().sendMessage(cancelHelp);

		String reloadText = PlotRedstone.getInstance().getConfig().getString("help.reload", "&eReload configuration.").replace("&", "§");
		TextComponent reloadHelp = new TextComponent("/pm reload  " + reloadText);
		reloadHelp.setColor(ChatColor.GRAY);
		reloadHelp.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/pm reload"));
		reloadHelp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(reloadText).color(ChatColor.BLUE).create()));
		commandSender.spigot().sendMessage(reloadHelp);
	}
}
